function findKeywordXHS (){
    let workItemXHS = className('android.widget.FrameLayout').depth('11').find()
    console.log(workItemXHS.length);
    workItemXHS = workItemXHS.filter(e=>e.childCount()&&e.bounds().height()>400)
    workItemXHS.forEach(e=>{
        if(e.child(0).childCount()==5 && e.child(0).child(3).child(2).child(1).text()=='赞')return
        if(e.child(0).childCount()==4 && e.child(0).child(2).child(2).child(1).text()=='赞')return
        e.click()
        const keywordNameXHS = className('android.widget.TextView').depth(13).drawingOrder(2).findOne(2000)
        const keywordTitleXHS = className('android.widget.TextView').depth(13).drawingOrder(3).findOne(2000)
        if(!keywordNameXHS){
            console.log('视频');
            const keywordNameXHS2 = className('android.widget.TextView').depth(12).drawingOrder(1).findOne(2000)
            const keywordTitleXHS2 = className('android.widget.TextView').depth(13).drawingOrder(1).findOne(2000)
            console.log(keywordNameXHS2.text());
            console.log(keywordTitleXHS2.text());
            const pingLunXHS2 = className('android.widget.Button').depth(10).drawingOrder(33).findOne(2000)
            if(pingLunXHS2.child(1).text()=='评论'){
                toastLog('没有评论')
                back()
                sleep(2000)
            }else{
                pingLunXHS2.click()

            }

        }else{
        console.log('图文');
        console.log(keywordNameXHS.text());
        console.log(keywordTitleXHS.text());
        sleep(2000)
        const pingLunXHS = className('android.widget.Button').depth(10).drawingOrder(4).findOne(2000)
        if(pingLunXHS.child(1).text()=='评论'){
            toastLog('没有评论')
            back()
            sleep(2000)
        }else{
            pingLunXHS.click()
            sleep(2000)
            swipe(
                device.width / 2,
                device.height * 0.5,
                device.width / 2,
                device.height * 0.8,
                1000
            )
            sleep(2000)
            const keywordTimeXHS = className('android.view.View').depth(13).drawingOrder(2).findOne(2000)
            console.log(keywordTimeXHS.desc());
            pingLunXHS.click()
            sleep(2000)
            JieLiuKeywordXHS()
            sleep(2000)
        }
        } 

    })
    swipe(
        device.width / 2,
        device.height * 0.9,
        device.width / 2,
        device.height * 0.1,
        1000
    )
    findKeywordXHS()
}
findKeywordXHS()
// 小红书抓取评论(图文)
function JieLiuKeywordXHS(){
    let pingLunItemXHS = className('android.widget.FrameLayout').depth(10).find()
    console.log(pingLunItemXHS.length);
    pingLunItemXHS = pingLunItemXHS.filter(e=>e.child(0).child(0)&&e.child(0).child(0).childCount()==3)
    let arr = []
    pingLunItemXHS.forEach(e=>{
        arr.push(e.child(0).child(0).child(0).bounds().height()) 
    })
    pingLunItemXHS.forEach(e=>{
        if(e.child(0).child(0).child(0).bounds().height() < findMax(arr))return
        console.log(e.child(0).child(0).child(1).child(0).child(0).text());
        console.log(e.child(0).child(0).child(1).child(1).text());
        e.child(0).child(0).child(0).click()
        sleep(2000)
        let keywordNameXHS = className('android.widget.TextView').depth(17).drawingOrder(2).findOne(2000)
        let keywordIPXHS = className('android.widget.TextView').depth(15).drawingOrder(16).findOne(2000)
        if(!keywordIPXHS){
            keywordNameXHS = className('android.widget.TextView').depth(16).drawingOrder(3).findOne(2000)
            keywordIPXHS = className('android.widget.TextView').depth(16).drawingOrder(1).findOne(2000)
        }
        console.log(keywordNameXHS.text());
        console.log(keywordIPXHS.text());
        back()
        sleep(2000)
    })
    const keywordBottom = className('android.widget.TextView').depth(12).drawingOrder(2).text("- 到底了 -").findOne(2000)
    if(keywordBottom){
        toastLog('到底了')
        back()
    }else{
        swipe(
            device.width / 2,
            device.height * 0.9,
            device.width / 2,
            device.height * 0.1,
            1500
        )
        JieLiuKeywordXHS()
    }
  }

function JieLiuKeywordXHS2(){
    let pingLunItemXHS = className('android.widget.LinearLayout').depth(14).find()
    console.log(pingLunItemXHS.length);
    let arr = []
    pingLunItemXHS.forEach(e=>{
        arr.push(e.child(0).child(0).bounds().height()) 
    })
    pingLunItemXHS.forEach(e=>{
        if(e.child(0).child(0).bounds().height() < findMax(arr))return
        console.log(e.child(0).child(1).child(0).child(0).text());
        console.log(e.child(0).child(1).child(1).text());
        e.child(0).child(0).click()
        sleep(2000)
        let keywordNameXHS = className('android.widget.TextView').depth(17).drawingOrder(2).findOne(2000)
        let keywordIPXHS = className('android.widget.TextView').depth(15).drawingOrder(16).findOne(2000)
        if(!keywordIPXHS){
            keywordNameXHS = className('android.widget.TextView').depth(16).drawingOrder(3).findOne(2000)
            keywordIPXHS = className('android.widget.TextView').depth(16).drawingOrder(1).findOne(2000)
        }
        console.log(keywordNameXHS.text());
        console.log(keywordIPXHS.text());
        back()
        sleep(2000)
    })
    const keywordBottom = className('android.widget.TextView').depth(15).drawingOrder(2).text("- 到底了 -").findOne(2000)
    if(keywordBottom){
        toastLog('到底了')
        back()
    }else{
        swipe(
            device.width / 2,
            device.height * 0.9,
            device.width / 2,
            device.height * 0.1,
            1500
        )
        JieLiuKeywordXHS2()
    }
}


function findMax(array) {
    let max = array[0];
    for (let i = 1; i < array.length; i++) {
        if (array[i] > max) {
            max = array[i];
        }
    }
    return max;
  }